#include "ChatClient.h"

int login(int sockfd)
{

string input;
string username,name,passwd;
while(1)
{
cout<<"login or signup?"<<endl;
cin>>input;
if(input=="login"||input=="signup")
input=datadeal(sockfd,input);
else cout<<"try again"<<endl;
cout<<input<<endl;
if(input=="login")
{

//write(sockfd,input.c_str(),sizeof(input.c_str()));
cout<<"please input user name:"<<endl;
cin>>name;
if(datadeal(sockfd,name)=="ok")
{
cout<<"please input passwd:"<<endl;
cin>>passwd;
if(datadeal(sockfd,passwd)=="ok")
{
username=name;
cout<<"login successfully"<<endl;
return 1;
}
else cout<<"passwd error"<<endl;
}
else cout<<"user don`t exist"<<endl;
}
else if(input=="signup")
{
//write(sockfd,input.c_str(),sizeof(input.c_str()));
cout<<"please input new user name:"<<endl;
cin>>name;
if(datadeal(sockfd,name)=="ok")
{
cout<<"please input passwd:"<<endl;
cin>>passwd;
if(datadeal(sockfd,passwd)=="ok")
cout<<"sign up successfully"<<endl;
}}}}
